package com.rui.study.algorithm.L_深入理解JVM_锁;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-03-05 14:45
 **/
public class Test extends AbstractQueuedSynchronizer {



    ConcurrentHashMap map = new ConcurrentHashMap();

    private void getAndIncrement(int count) {
        System.out.println(Thread.currentThread().getName() + ":" + compareAndSetState(0, count));
    }


    private void demo() {
        ClassLoader k = ClassLoader.getSystemClassLoader();
        map.put("sk", "heh");
    }

    public static void main(String[] args) {
        Test test = new Test();
        CyclicBarrier barrier = new CyclicBarrier(10);
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                try {
                    barrier.await();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                test.getAndIncrement(1);
            }, "My-thread-" + i).start();
        }
    }
}
